package com.ipartek.dadoweb.util;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Application Lifecycle Listener implementation class ServerListener
 * 
 */
public class InitServletListener implements ServletContextListener {

	protected static Properties propertiesMsg;
	static final private String PATH_PROPERTIES_MSG = "/WEB-INF/config/msg.properties";

	/**
	 * Default constructor.
	 */
	public InitServletListener() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see ServletContextListener#contextInitialized(ServletContextEvent)
	 */
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		propertiesMsg = new Properties();
		try {
			propertiesMsg.load(sce.getServletContext().getResourceAsStream(
					PATH_PROPERTIES_MSG));
			sce.getServletContext().setAttribute("mensages", propertiesMsg);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @see ServletContextListener#contextDestroyed(ServletContextEvent)
	 */
	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		propertiesMsg = null;
		sce.getServletContext().removeAttribute("mensages");
	}

}
